package com.company.gxcpc2018;

import java.util.Scanner;

public class Gxcpc8 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            sc.nextLine();
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += sc.nextLine().length();
            }
            System.out.println(sum);
        }
    }
}
